// pages/common/list/list.js
Component({
	/**
	 * 组件的属性列表
	 */
	properties: {
		loading: {
			type: Boolean,
			value: false,
		},
		finish: {
			type: Boolean,
			value: false,
		},
	},

	/**
	 * 组件的初始数据
	 */
	data: {
		currentY: 0,
		y: 0,
		touch: false,
		end: false,
	},
	/**
	 * 组件的方法列表
	 */
	ready() {
		var val
		Object.defineProperty(this.data, 'loading', {
			configurable: true,
			enumerable: true,
			set: value => {
				val = value
				// console.log(value)
				if (!val) {
					this.setData({
						y: 0,
						currentY: 0,
						end: false,
					})
					// console.log(this.data)
				}
			},
			get: () => {
				return val
			},
		})
	},
	methods: {
		handleMovableChange: function (e) {
			if (!this.data.touch) {
				return
			}
			this.setData({
				currentY: e.detail.y,
			})
			// if (this.data.currentY > 20) {
			//   this.setData({
			//     y: this.data.currentY
			//   });
			// }
			// console.log(this.data.currentY)
		},
		handleTouchend: function (e) {
			if (this.data.currentY > 20) {
				// console.log(this.data.currentY)
				this.setData({
					touch: false,
					y: 50,
					// this.data.currentY - 20 > 50 ? 50 : this.data.currentY - 20
					loading: true,
				})
				this.triggerEvent('request', 'refresh')
			}
		},
		handleTouchestart: function (e) {
			this.setData({
				touch: true,
			})
		},
		getMore() {
			if (this.data.finish || this.data.loading) {
				return
			}
			this.setData({
				end: true,
			})
			setTimeout(() => {
				this.setData({
					loading: true,
				})
			}, 0)
			this.triggerEvent('request', 'query')
		},
	},
})
